package com.j48.entrancegurad.mapper;

import com.j48.entrancegurad.model.Host;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

/**
 * host表操作
 */
@Repository
@Mapper
public interface HostMapper {
    /**
     * 查询所有业主
     * @return 业主列表
     */
    @Select("select * from `host`")
    public ArrayList<Host> selectAll();
    /**
     * 按编号查询业主
     * @param host 查询条件
     * @return 查询结果
     */
    @Select("select * from host where host_id=#{host_id}")
    public Host selectById(Host host);
    /**
     * 按电话号码查询业主
     * @param host 查询条件
     * @return 查询结果
     */
    @Select("select * from host where host_phone=#{host_phone}")
    public Host selectByPhone(Host host);

    /**
     * 按编号查询业主
     * @param host 查询条件
     * @return 查询结果
     */
    @Select("select * from host where host_id=#{host_id}")
    public ArrayList<Host> selectById1(Host host);

    /**
     * 按姓名查询业主
     * @param host 查询条件
     * @return 查询结果
     */
    @Select("select * from host where host_name=#{host_name}")
    public ArrayList<Host> selectByName(Host host);

    /**
     * 按房屋查询业主
     * @param host 查询条件
     * @return 查询结果
     */
    @Select("select * from `host` where host_building=#{host_building} and host_unit=#{host_unit} and host_housenumber=#{host_housenumber}")
    public Host selectByHouse(Host host);

    /**
     * 添加业主
     * @param host 被添加业主
     * @return 影响数据库数据条数
     */
    @Insert("insert into `host`(host_building,host_unit,host_housenumber,host_name,host_phone,host_number,host_create_admin_id,host_createtime) values (#{host_building},#{host_unit},#{host_housenumber},#{host_name},#{host_phone},#{host_number},#{host_create_admin_id},#{host_createtime})")
    public int insert(Host host);

    /**
     * 当前业主所拥有用户数量+1
     * @param host 被影响业主
     * @return 影响数据库数据条数
     */
    @Update("update `host` set host_number=#{host_number}+1 where host_id=#{host_id}")
    public int hostnumberAdd(Host host);
    /**
     * 更新业主信息
     * @param host 更新后的业主信息
     * @return 影响数据库数据条数
     */
    @Update("update `host` set host_name=#{host_name},host_phone=#{host_phone},host_number=#{host_number} where host_id=#{host_id}")
    public int update(Host host);
}
